<template>
	<view class="content">
		<view class="progress-box" v-if="jinduShow"><progress :percent="percent" show-info stroke-width="3" /></view>
		<view class="lunbo">
			<swiper indicator-dots="true" autoplay="true" interval="5000" circular="true" duration="1000">
				<swiper-item v-for="(val, index) in imgArr" :key="index">
					<navigator v-if="val.newsId" class="swiper-item" :url="'../news/newsDetail?newsId=' + val.newsId">
						<image :src="val.imgUrl"></image>
					</navigator>
					<view v-else class="swiper-item">
						<image :src="val.imgUrl"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="tongzhi">
			<view class="uni-swiper-msg">
				<view class="uni-swiper-msg-icon">
					<image src="https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png" mode="widthFix"></image>
				</view>
				<swiper vertical="true" autoplay="true" circular="true" interval="3000">
					<swiper-item v-for="(item, index) in msgArr" :key="index">
						<navigator :url="'../tongzhi/tongzhixiangqing?xqId=' + item.noticeId" class="uni-ellipsis">{{ item.noticeTitle }}</navigator>
					</swiper-item>
				</swiper>
				<navigator class="more" url="../tongzhi/tongzhi">更多</navigator>
			</view>
		</view>
		<view class="uni-grid-9 uni-common-mt">
			<view class="uni-grid-9-item" hover-class="uni-grid-9-item-hover" v-for="(item, index) in grids" :key="index" :class="index % 3 === 2 ? 'no-border-right' : ''"
			 @tap="goRepair(index)">
				<image class="uni-grid-9-image" :src="item.src"></image>
				<text class="uni-grid-9-text">{{ item.tip }}</text>
			</view>
		</view>
		<view style="width: 200rpx;height: 200rpx;" @longpress="opendLog"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				fanhui: '',
				url_can: '1321',
				msgArr: [],
				jinduShow: false,
				percent: 0,
				Url: '',
				benjiversion: '',
				src: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/shuijiao.jpg',
				grids: [{
						src: '../../static/img/bx.jpg',
						tip: '我要报修'
					},
					{
						src: '../../static/img/tx.jpg',
						tip: '报修记录'
					},
					{
						src: '../../static/img/xx.jpg',
						tip: '帮助手册'
					},
					{
						src: '../../static/img/bc.jpg',
						tip: '新闻动态'
					},
					{
						src: '../../static/img/xy.jpg',
						tip: '校园地图'
					},
					{
						src: '../../static/img/fw.jpg',
						tip: '报修电话'
					}
				],
				imgArr: ['../../static/img/20181023223414018104.jpg', '../../static/img/20181220153508973251.jpg',
					'../../static/img/20190104170243832377.png'
				]
			};
		},
		computed: mapState(['URL', 'TOKEN', 'USER_INFO']),
		onLoad() {
			uni.showLoading({
				title: '获取信息中'
			});
			// console.log(this.URL);
			this.GET_USER_INFO();
			this.GET_TOKEN();
			this.getNotice();
			this.getAtlas();
			setTimeout(() => {
				this.parseUrl();
			}, 1000)
		},
		methods: {
			...mapMutations(['LOGIN', 'GET_USER_INFO', 'GET_TOKEN', 'SHOW_LOGIN']),
			opendLog(){
				uni.navigateTo({
					url:"/pages/log/log"
				})
			},
			parseUrl: function() {
				// 获取code
				if (window.location.href.indexOf("?") != -1) {
					var searchHref = window.location.href.split('?')[1];
					var params = searchHref.split('&');
					var returnParam = {};
					params.forEach(function(param) {
						var paramSplit = param.split('=');
						returnParam[paramSplit[0]] = paramSplit[1];
					});
					console.log(returnParam.code);

					//推送code,拉取 个人信息
					uni.request({
						url: this.URL + 'getUserInfo?code='+returnParam.code,
						method: 'GET',
						// data: {
						// 	code: returnParam.code
						// },
						success: res => {
							this.fanhui = res.data;
							console.log(res.data.user);
							this.LOGIN(res.data.user);
							uni.hideLoading();
							// uni.showToast({
							// 	title:res.data.user
							// })

							// {
							//     "errcode": 0,
							//     "errmsg": "ok",
							//     "userid": "15614387834",
							//     "name": "赵崇焕--基建处报修平台调试工程师",
							//     "department": [
							//         2322
							//     ],
							//     "mobile": "15614387834",
							//     "gender": "1",
							//     "weixinid": "buziran1",
							//     "avatar": "http://shp.qpic.cn/bizmp/iaPxcvzpDN7YJdtW51y49uOQH9FnvfS6GDnHcZJXM1ibjzkUQ4gPjHOg/",
							//     "status": 1,
							//     "extattr": {
							//         "attrs": [
							//             {
							//                 "name": "身份证号后六位",
							//                 "value": "072915"
							//             }
							//         ]
							//     }
							// }



							// this.LOGIN({
							// 	"id": "092a3a7ee29b11e98db200163e0c01db",
							// 	"miniOpenId": null,
							// 	"sessionKey": null,
							// 	"nickName": null,
							// 	"wxToken": null,
							// 	"wxOpenId": null,
							// 	"uid": null,
							// 	"name": "赵崇焕",
							// 	"phoneNumber": "15614387834",
							// 	"token": "db2e69d286244c9d868f564323d6ffca",
							// 	"tokenTime": null
							// })
						}
					});

				}

			},
			getNotice() {
				let data = {
					page: 1,
					rows: 5
				};
				uni.request({
					url: this.URL + 'notice/getNoticeList',
					data: data,
					success: res => {
						this.msgArr = res.data.data;
						// console.log(res.data);
					}
				});
			},
			getAtlas() {
				uni.request({
					url: this.URL + 'img/getImgList',
					success: res => {
						// console.log("lunbo");
						this.imgArr = res.data.data;
					}
				});
			},
			goRepair(e) {
				// if (this.USER_INFO) {
				if (e === 0) {
					if (this.USER_INFO) {
						uni.navigateTo({
							url: '../baoxiu/baoxiu'
						});
					} else {
						this.SHOW_LOGIN();
					}
				} else if (e === 1) {
					if (this.USER_INFO) {
						uni.navigateTo({
							url: '../baoxiuList/baoxiuList'
						});
					} else {
						this.SHOW_LOGIN();
					}
				} else if (e === 3) {
					uni.navigateTo({
						url: '../news/news'
					});
				} else if (e === 4) {
					uni.navigateTo({
						url: '../map/map'
					});
				} else if (e === 5) {
					uni.navigateTo({
						url: '../addressBook/addressBook'
					});
				} else if(e ===2){
					uni.navigateTo({
						url: '../help/help'
					});
				}
				// } else {
				// this.SHOW_LOGIN();
				// }
			}
		}
	};
</script>

<style>
	/* 轮播演示覆盖 */
	.lunbo swiper {
		width: calc(750upx - 40upx);
		height: 450upx;
	}

	.lunbo swiper image {
		width: 100%;
		height: 450upx;
	}

	.tongzhi {
		margin-top: 20upx;
	}

	.more {
		padding-left: 20upx;
		width: 100upx;
	}

	.more:after {
		content: '';
		width: 2upx;
		height: 30upx;
		display: inline-block;
		background: #cfd0d2;
		position: relative;
		top: 5upx;
		left: -70upx;
	}

	/* 导航 */
	.uni-grid-9 {
		margin-top: 0upx;
		background: white;
		width: calc(750upx - 40upx);
	}

	.uni-grid-9-item {
		width: 33.33%;
		box-sizing: border-box;
	}

	.uni-grid-9-text {
		line-height: 50upx;
	}
</style>
